//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "LossDistHomogeneous.h"
using namespace Cephei::QL::Experimental::Credit;
#include <gen/QL/Experimental/Credit/LossDist.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (UInt64 nBuckets, Double maximum, Microsoft::FSharp::Core::FSharpOption<Double>^ epsilon) : CLossDist(CLossDistHomogeneous::typeid)
{
    try
    {
#ifdef HANDLE
        _phLossDistHomogeneous = NULL;
#endif
        QuantLib::Size _nBuckets = (QuantLib::Size)ValueHelper::Convert (nBuckets); //d
        QuantLib::Real _maximum = (QuantLib::Real)ValueHelper::Convert (maximum); //d
        QuantLib::Real _epsilon = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (epsilon) ? (QuantLib::Real)ValueHelper::Convert (epsilon->Value) : 1e-6); //4
        _ppLossDistHomogeneous = new boost::shared_ptr<QuantLib::LossDistHomogeneous> (new QuantLib::LossDistHomogeneous ( _nBuckets,  _maximum,  _epsilon ));
        SetLossDist (boost::dynamic_pointer_cast<QuantLib::LossDist> (*_ppLossDistHomogeneous));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (boost::shared_ptr<QuantLib::LossDistHomogeneous>& childNative, Object^ owner) : CLossDist(CLossDistHomogeneous::typeid)
{
#ifdef HANDLE
	_phLossDistHomogeneous = NULL;
#endif
	_ppLossDistHomogeneous = &childNative;
    _ppLossDist = new boost::shared_ptr<QuantLib::LossDist> (boost::dynamic_pointer_cast<QuantLib::LossDist> (*_ppLossDistHomogeneous));
}
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (QuantLib::LossDistHomogeneous& childNative, Object^ owner) : CLossDist(CLossDistHomogeneous::typeid)
{
#ifdef HANDLE
	_phLossDistHomogeneous = NULL;
#endif
	_ppLossDistHomogeneous = new boost::shared_ptr<QuantLib::LossDistHomogeneous> (&childNative);
    _ppLossDist = new boost::shared_ptr<QuantLib::LossDist> (boost::dynamic_pointer_cast<QuantLib::LossDist> (*_ppLossDistHomogeneous));
    _LossDistHomogeneousOwner = owner;
    _LossDistOwner = owner;
}

Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (CLossDistHomogeneous^ copy) : CLossDist(CLossDistHomogeneous::typeid)
{
#ifdef HANDLE
	_phLossDistHomogeneous = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppLossDistHomogeneous = new boost::shared_ptr<QuantLib::LossDistHomogeneous> (copy->GetShared());
        _ppLossDist = new boost::shared_ptr<QuantLib::LossDist> (boost::dynamic_pointer_cast<QuantLib::LossDist> (*_ppLossDistHomogeneous));
    }
}
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (PLATFORM::Type^ t) : CLossDist(CLossDistHomogeneous::typeid)
{
#ifdef HANDLE
	_phLossDistHomogeneous = NULL;
#endif
	if (!t->IsSubclassOf(CLossDistHomogeneous::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (QuantLib::Handle<QuantLib::LossDistHomogeneous>& childNative, Object^ owner)  : CLossDist(CLossDistHomogeneous::typeid)
{
	_phLossDistHomogeneous = &childNative;
	_ppLossDistHomogeneous = &static_cast<boost::shared_ptr<QuantLib::LossDistHomogeneous>>(childNative.currentLink());
    _ppLossDist = new boost::shared_ptr<QuantLib::LossDist> (boost::dynamic_pointer_cast<QuantLib::LossDist> (*_ppLossDistHomogeneous));
    _LossDistHomogeneousOwner = owner;
}
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (QuantLib::Handle<QuantLib::LossDistHomogeneous> childNative)  : CLossDist(CLossDistHomogeneous::typeid)
{
	_phLossDistHomogeneous = &childNative;
	_ppLossDistHomogeneous = &static_cast<boost::shared_ptr<QuantLib::LossDistHomogeneous>>(childNative.currentLink());
    _ppLossDist = new boost::shared_ptr<QuantLib::LossDist> (boost::dynamic_pointer_cast<QuantLib::LossDist> (*_ppLossDistHomogeneous));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::CLossDistHomogeneous (QuantLib::LossDistHomogeneous childNative)  : CLossDist(CLossDistHomogeneous::typeid)
{
#ifdef HANDLE
	_phLossDistHomogeneous = NULL;
#endif
	_ppLossDistHomogeneous = new boost::shared_ptr<QuantLib::LossDistHomogeneous> (new QuantLib::LossDistHomogeneous (childNative));
    _ppLossDist = new boost::shared_ptr<QuantLib::LossDist> (boost::dynamic_pointer_cast<QuantLib::LossDist> (*_ppLossDistHomogeneous));
}
#endif

Cephei::QL::Experimental::Credit::CLossDistHomogeneous::~CLossDistHomogeneous ()
{
    if (_ppLossDistHomogeneous != NULL)
    {
	    delete _ppLossDistHomogeneous;
        _ppLossDistHomogeneous = NULL;
    }
}
Cephei::QL::Experimental::Credit::CLossDistHomogeneous::!CLossDistHomogeneous ()
{
    if (_ppLossDistHomogeneous != NULL)
    {
	    delete _ppLossDistHomogeneous;
    }
}
QuantLib::LossDistHomogeneous& Cephei::QL::Experimental::Credit::CLossDistHomogeneous::GetReference ()
{
    if (_ppLossDistHomogeneous == NULL) throw REFNEW NativeNullException ();
	return **_ppLossDistHomogeneous;
}
boost::shared_ptr<QuantLib::LossDistHomogeneous>& Cephei::QL::Experimental::Credit::CLossDistHomogeneous::GetShared ()
{
    if (_ppLossDistHomogeneous == NULL) throw REFNEW NativeNullException ();
	return *_ppLossDistHomogeneous;
}
QuantLib::LossDistHomogeneous* Cephei::QL::Experimental::Credit::CLossDistHomogeneous::GetPointer ()
{
    if (_ppLossDistHomogeneous == NULL) throw REFNEW NativeNullException ();
	return &**_ppLossDistHomogeneous;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::LossDistHomogeneous>& Cephei::QL::Experimental::Credit::CLossDistHomogeneous::GetHandle ()
{
	if (_phLossDistHomogeneous == NULL)
	{
		_phLossDistHomogeneous = new Handle<QuantLib::LossDistHomogeneous> (*_ppLossDistHomogeneous);
	}
	return *_phLossDistHomogeneous;
}
#endif
bool Cephei::QL::Experimental::Credit::CLossDistHomogeneous::HasNative () 
{
	return (_ppLossDistHomogeneous != NULL);
}

UInt64 Cephei::QL::Experimental::Credit::CLossDistHomogeneous::Buckets::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppLossDistHomogeneous)->buckets ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Credit::CLossDistHomogeneous::ExcessProbability::get ()
{
    try
    {
    	std::vector<QuantLib::Real> _rv = (std::vector<QuantLib::Real>)(*_ppLossDistHomogeneous)->excessProbability ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Credit::CLossDistHomogeneous::Maximum::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppLossDistHomogeneous)->maximum ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Credit::CLossDistHomogeneous::Probability::get ()
{
    try
    {
    	std::vector<QuantLib::Real> _rv = (std::vector<QuantLib::Real>)(*_ppLossDistHomogeneous)->probability ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Experimental::Credit::CLossDistHomogeneous::Size::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppLossDistHomogeneous)->size ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Credit::CLossDistHomogeneous::Volume::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppLossDistHomogeneous)->volume ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Credit::ILossDistHomogeneous^ Cephei::QL::Experimental::Credit::CLossDistHomogeneous_Factory::Create (UInt64 nBuckets, Double maximum, Microsoft::FSharp::Core::FSharpOption<Double>^ epsilon)
{
    return REFNEW CLossDistHomogeneous ( nBuckets,  maximum,  epsilon);
}
